package ru.spb.xmlreshelper.gui;

import javax.swing.*;
import java.awt.*;

/**
 * @author Nikita.Brazhnikov
 */
public class FieldLabelPair {

	private String key;

	private JTextField field;
	private JLabel label;


	public FieldLabelPair(String labelText) {
		field = new JTextField(10);
		label = new JLabel(labelText);
		label.setLabelFor(field);
		key = labelText;
	}

	public JTextField getField() {
		return field;
	}

	public JLabel getLabel() {
		return label;
	}

	public FieldLabelPair addSeparate(Container container) {
		container.add(label);
		container.add(field);
		return this;
	}

	public FieldLabelPair addTogether(Container container) {
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(label);
		panel.add(field);
		container.add(panel);
		return this;
	}

	public static FieldLabelPair create(String label) {
		return new FieldLabelPair(label);
	}

	public FieldLabelPair width(int width) {
		field.setColumns(width);
		return this;
	}

	public static FieldLabelPair empty() {
		FieldLabelPair pair = new FieldLabelPair("");
		pair.field.setVisible(false);
		pair.label.setVisible(false);
		return pair;
	}

	public String getKey() {
		return key;
	}

	public String getValue() {
		return field.getText();
	}

    public void setFieldValue(String value) {
        this.field.setText(value);
    }
}
